package com.pronhub.shop.cloud;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    //响应200是正常的 500系列是登录错误的 其他再说
    private Integer code;//返回的代码
    private String msg;//返回的信息
    private T data;//泛型的数据类型
    public static final Integer DEFAULT_SUCCESS_CODE = 200;
    public static final String DEFAULT_SUCCESS_MSG="操作成功";

    public static final Integer DEFAULT_ERROR_CODE = 500;
    public static final String DEFAULT_ERROR_MSG="服务器操蛋中,等下再试";


    public static <T> Result<T> success(T data){
        return new Result(DEFAULT_SUCCESS_CODE,DEFAULT_SUCCESS_MSG,data);
    }
    public static <T> Result<T> success(T data,String msg){
        return new Result(DEFAULT_SUCCESS_CODE,msg,data);
    }
    public static <T> Result<T> defaultError(){
        return new Result(DEFAULT_ERROR_CODE,DEFAULT_ERROR_MSG,null);
    }
    public static <T> Result<T> error(CodeMSg codeMSg){
        return new Result(codeMSg.getCode(),codeMSg.getMsg(),null);
    }

    public boolean hasError(){
        //状态吗！=200 说明有错误.
        return this.code!=DEFAULT_SUCCESS_CODE;
    }
}


